(ns tala.test.rdf
  (:use tala.rdf)
  (:use clojure.test)
  (:import org.mulgara.mrg.Uri
           org.mulgara.mrg.Literal
           org.mulgara.mrg.Triple
           org.mulgara.mrg.vocab.RDF
           org.mulgara.mrg.vocab.FOAF))

(deftest test-simple-graph
  (let [n (Uri. "http://nxg.me.uk/norman/")]
    (let [g (make-simple-graph (lazy-seq [[n RDF/TYPE FOAF/PERSON] ;Uri/Uri/Uri
                                          [n FOAF/NAME (Literal. "Norman Gray")] ;Uri/Uri/Literal
                                          [(java.net.URI. "http://nxg.me.uk/norman/") ;URI, not Uri
                                           (.resolve (.getURI FOAF/BASE_URI) "mbox") ;URI, not Node
                                           (java.net.URI. "mailto:norman@astro.gla.ac.uk")] ;URI, not Literal
                                          [n
                                           (java.net.URI. "http://xmlns.com/foaf/0.1/givenname") ;URI, not Node
                                           "Norman"] ;literal, not Node
                                          ]))]
      (is (= 4 (.size g)))
      (is (.isAsserted g (Triple. n RDF/TYPE FOAF/PERSON)))
      (is (.isAsserted g (Triple. n FOAF/NAME (Literal. "Norman Gray"))))
      (is (.isAsserted g (Triple. n (Uri. "http://xmlns.com/foaf/0.1/mbox") (Uri. "mailto:norman@astro.gla.ac.uk"))))
      (is (.isAsserted g (Triple. n (Uri. "http://xmlns.com/foaf/0.1/givenname") (Literal. "Norman")))))))

(deftest test-make-graph-bad-arguments
  (let [u (Uri. "urn:foo")]
    (is (thrown? java.lang.IllegalArgumentException
                 (make-simple-graph (seq [["foo" u     u]]))))
    (is (thrown? java.lang.IllegalArgumentException
                 (make-simple-graph (seq [[u     "foo" u]]))))
    (is (thrown? java.lang.IllegalArgumentException
                 (make-simple-graph (seq [[u     u     1]]))))))

